package com.myteam.mystory.service;

import java.util.ArrayList;
import java.util.List;

import com.myteam.mystory.DAO.CreateDatabase;
import com.myteam.mystory.DAO.ParamDAO;
import com.myteam.mystory.DAO.StoriesDAO;
import com.myteam.mystory.entity.ParamEntity;
import com.myteam.mystory.entity.StoriesEntity;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

public class StoriesService {
	private final Context context;

	public StoriesService(Context context) {
		super();
		this.context = context;
	}
	
	public long insert_story(StoriesEntity storiesEntity){
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		StoriesDAO storiesDAO = new StoriesDAO(db);
		long result = storiesDAO.insert_story(storiesEntity);
		db.close();
		createDb.close();
		return result;
	}
	
	public ArrayList<StoriesEntity> getAllStory() {
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		StoriesDAO storiesDAO = new StoriesDAO(db);
		ArrayList<StoriesEntity> list_story = new ArrayList<StoriesEntity>();
		list_story = storiesDAO.getAllStory();
		db.close();
		createDb.close();
		return list_story;
	}
	public List<String> getNameStory(){
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		StoriesDAO storiesDAO = new StoriesDAO(db);
		List<String> listnameStory = new ArrayList<String>();
		listnameStory = storiesDAO.getNameStory();
		db.close();
		createDb.close();
		return listnameStory;
	}
	public List<String> getStoryID(){
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		StoriesDAO storiesDAO = new StoriesDAO(db);
		List<String> listStoryID = new ArrayList<String>();
		listStoryID = storiesDAO.getStoryID();
		db.close();
		createDb.close();
		return listStoryID;
	}
	
	public List<Integer> getViewCount(){
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		StoriesDAO storiesDAO = new StoriesDAO(db);
		List<Integer> listViewCount = storiesDAO.getViewCount();
		db.close();
		createDb.close();
		return listViewCount;
	}
	
	public List<Integer> getlikeCount(){
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		StoriesDAO storiesDAO = new StoriesDAO(db);
		List<Integer> listlikeCount = storiesDAO.getlikeCount();
		db.close();
		createDb.close();
		return listlikeCount;
	}
	
	public long deleteTableStory(){
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		StoriesDAO storiesDAO = new StoriesDAO(db);
		long result = storiesDAO.deleteTableStory();
		db.close();
		createDb.close();
		return result;
	}
}
